<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>批量管理</title>
    <link rel="stylesheet" href="css/base.css" />
    <link rel="stylesheet" href="css/all.css" />
    <link rel="stylesheet" href="css/iconfont.css" />
    <link rel="stylesheet" href="css/batch-management.css" />
<body>
<div>
    <div class="head">
         <span href="javascript:;" onclick="go()">
        <i class="iconfont icon-iconfontjiantou1"></i></span>
        <h1 class="titles">批量管理</h1>
    </div>
    <div class="middles">
    	<div id="batch">
    		<!--<div class="commodity row">
	            <div class="check">
	                <i class="iconfont icon-xuanzhong1"></i>
	            </div>
	            <div class="commoditys">
	                <div class="picture">
	                    <img src="img/shangpin.png" alt="">
	                </div>
	                <p>灯具</p>
	                <p>￥150.00</p>
	                <p>总销量 10</p>
	            </div>
	        </div>
	        <div class="commodity row">
	            <div class="check">
	                <i class="iconfont icon-xuanzhong1 picth"></i>
	            </div>
	            <div class="commoditys">
	                <div class="picture">
	                    <img src="img/shangpin.png" alt="">
	                </div>
	                <p>灯具</p>
	                <p>￥150.00</p>
	                <p>总销量 10</p>
	            </div>
	        </div>-->
    	</div>
	      
        <div class="solds flex">
            <div>
                <input type="button" class="sold" value="下架" onclick="xiajiaProduct()"/>
            </div>
            <div>
                <input type="button" class="sold" value="删除" onclick="deleteProduct()"/>
            </div>
        </div>
    </div>
</div>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/x_rem.js"></script>
<script src="js/all.js"></script>
<script type="text/javascript">
	//先获取上架商品
	$(function() {
				var data = JSON.stringify({
					"index": 0,
					"size": 10,
					"status": 0
				});

				var succrss = (data) => {
					console.log(data.message.code);

					if(data.message.code == 200) {
						var html = "";

						for(let i = 0; i<data.data.productList.length; i++) {
							html += `
	    		  				<div class="commodity row">
						            <div class="check">
						                <input type="checkbox" value="${data.data.productList[i].productId}" class="checkoutProduct"/>
						            </div>
						            <div class="commoditys">
						                <div class="picture">
						                    <img src="img/shangpin.png" alt="">
						                </div>
						                <p>${data.data.productList[i].title}</p>
						                <p>￥${data.data.productList[i].nowPrice}</p>
						                <p>总销量  ${data.data.productList[i].saleAmount}</p>
						            </div>
						        </div>
    		   
    		  				`
						}
						
						$("#batch").html(html);
						

					} else {
						popup(data.message.msg);
					}
				};

				Hajax("post", "/supplier/product/getProductInfo", data, succrss);
				//  	optlons

			});

    function xiajiaProduct() {
        var productIdList = [];
        $(".checkoutProduct:checked").each(function () {
            productIdList.push($(this).val());
        });
        var data = {
            "productIdList":productIdList,
            "status":1
        }
        localStorage.setItem("userId", userId);
        localStorage.setItem("token", token);
        $.ajax({
            type: "POST",
            url: "/supplier/product/batchEdit",
            contentType: "application/json;charset=utf-8",
            data : JSON.stringify(data),
            dataType: "json",
            beforeSend: function(XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("token", token);
                XMLHttpRequest.setRequestHeader("userId", userId);
            },
            error: function(request) {
                alert("Connection error ");
            },
            success: function (data) {
                if (data.message.code == 200) {
                    location.reload();
                } else {
                    console.log(data.message.msg)
                    layer.alert(data.message.msg);
                }
            }
        });
    }
    
    function deleteProduct() {
        var productIdList = [];
        $(".checkoutProduct:checked").each(function () {
            productIdList.push($(this).val());
        });
        var data = {
            "productIdList":productIdList,
            "status":2
        }
        localStorage.setItem("userId", userId);
        localStorage.setItem("token", token);
        $.ajax({
            type: "POST",
            url: "/supplier/product/batchEdit",
            contentType: "application/json;charset=utf-8",
            data : JSON.stringify(data),
            dataType: "json",
            beforeSend: function(XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("token", token);
                XMLHttpRequest.setRequestHeader("userId", userId);
            },
            error: function(request) {
                alert("Connection error ");
            },
            success: function (data) {
                if (data.message.code == 200) {
                    location.reload();
                } else {
                    console.log(data.message.msg)
                    layer.alert(data.message.msg);
                }
            }
        });
    }
	
	
</script>

</body>
</html>